package com.woniuxy.his.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.woniuxy.his.entity.Case;
import com.woniuxy.his.entity.Prescription;
import com.woniuxy.his.mapper.CaseMapper;
import com.woniuxy.his.mapper.PrescriptionMapper;
import com.woniuxy.his.service.IPrescriptionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 处方表 服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2021-08-25
 */
@Service
public class PrescriptionServiceImpl extends ServiceImpl<PrescriptionMapper, Prescription> implements IPrescriptionService {

    @Resource
    private PrescriptionMapper prescriptionMapper;

    @Resource
    private CaseMapper caseMapper;

    @Override
    public Integer setIsGiveMedicineStatu(Integer prescriptionId) {
        //根据处方id查询并修改已付款未出药处方
        UpdateWrapper<Prescription> prescriptionUpdateWrapper = new UpdateWrapper<>();
        prescriptionUpdateWrapper.set("is_give_medicine", "yes").eq("prescription_id", prescriptionId);
        int i = prescriptionMapper.update(null, prescriptionUpdateWrapper);
        return i;
    }


    //修改药方是否付费
    @Override
    public Integer setIsPaidOfPrescription(Integer prescriptionId) {
        UpdateWrapper<Prescription> prescriptionUpdateWrapper = new UpdateWrapper<>();
        prescriptionUpdateWrapper.set("ispaid", "yes").eq("prescription_id", prescriptionId);
        int num = prescriptionMapper.update(null, prescriptionUpdateWrapper);
        return num;
    }
}
